package net.heartbeat.handler.listeners.console;

import java.util.Collection;

import net.heartbeat.handler.AbsenceListener;

public class ConsoleAbsenceListener implements AbsenceListener {
	@Override
	public void onAbsent(Collection<String> recentlyAbsent) {
		System.out.println(makeInfo(recentlyAbsent));
	}
	
	private String makeInfo(Collection<String> recentlyAbsent){
		if(recentlyAbsent.isEmpty()){
			return "[最近掉线]（无）";
		}
		
		StringBuilder info = new StringBuilder();
		info.append("[最近掉线]");
		boolean isFirst = true;
		for (String source : recentlyAbsent) {
			if (isFirst) {
				isFirst = false;
				info.append(source);
			} else {
				info.append(", " + source);
			}
		}
		
		return info.toString();
	}
}
